package com.example.rabbitmqbootproducer.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.example.rabbitmqbootproducer.constant.MessageConstant.*;


/**
 * 广播模式配置
 *
 * @author 伯路平
 * @since 2023/6/20
 **/
@Configuration
public class FanoutRabbitConfig {
    @Bean
    public Queue getFanoutQueueInstance1(){
        return new Queue(FANOUT_QUEUE_NAME1,true);
    }

    @Bean
    public Queue getFanoutQueueInstance2(){
        return new Queue(FANOUT_QUEUE_NAME2,true);
    }

    @Bean
    public Queue getFanoutQueueInstance3(){
        return new Queue(FANOUT_QUEUE_NAME3,true);
    }

    @Bean
    public FanoutExchange getFanoutExchangeInstance(){
        return new FanoutExchange(FANOUT_EXCHANGE_NAME,true,false);
    }

    @Bean
    public Binding getBinding1(){
        return BindingBuilder.bind(getFanoutQueueInstance1()).to(getFanoutExchangeInstance());
    }

    @Bean
    public Binding getBinding2(){
        return BindingBuilder.bind(getFanoutQueueInstance2()).to(getFanoutExchangeInstance());
    }

    @Bean
    public Binding getBinding3(){
        return BindingBuilder.bind(getFanoutQueueInstance3()).to(getFanoutExchangeInstance());
    }
}
